import Vue from "vue";
import {
  offerUploadQueue,
  startUploadQueue,
  stopUploadQueue
} from "@/bus/uploadHandler";

import {
  startDownloadQueue,
  stopDownloadQueue,
  offerDownloadQueue
} from "@/bus/downloadHandler";

const bus = new Vue();
const install = Vue => {
  if (install.installed) return;
  install.installed = true;
  Object.defineProperties(Vue.prototype, {
    $bus: {
      get() {
        return bus;
      }
    }
  });
};

bus.$on("startUploadQueue", () => startUploadQueue());
bus.$on("stopUploadQueue", () => stopUploadQueue());
bus.$on("offerUploadQueue", (filepath, parentId) =>
  offerUploadQueue(filepath, parentId)
);

bus.$on("startDownloadQueue", () => startDownloadQueue());
bus.$on("stopDownloadQueue", () => stopDownloadQueue());
bus.$on("offerDownloadQueue", (fileId, filename) =>
  offerDownloadQueue(fileId, filename)
);

export default install;
